package com.maiyawx.mall.util;

import com.maiyawx.mall.entity.Result;
import com.maiyawx.mall.enums.CommonEnum;

/**
 * 公共返回值
 */
public class ResultUtil {
    /**
     * 成功有值
     * @param data
     * @return
     */
    public static Result success(Object data)
    {
        Result result = new Result();
        result.setCode(CommonEnum.SUCCESS.getCode());
        result.setData(data);
        result.setMessage(CommonEnum.SUCCESS.getMessage());
        return result;
    }

    /**
     * 成功无值
     * @return
     */
    public static Result success()
    {
        return success(null);
    }

    /**
     * 失败
     * @param code
     * @param message
     * @return
     */
    public static Result error(Integer code,String message)
    {
        Result result = new Result();
        result.setCode(code);
        result.setData(null);
        result.setMessage(message);
        return result;
    }

    /**
     * 失败
     * @param commonEnum
     * @return
     */
    public static Result error(CommonEnum commonEnum)
    {
        Result result = new Result();
        result.setCode(commonEnum.getCode());
        result.setData(null);
        result.setMessage(commonEnum.getMessage());
        return result;
    }
}
